<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8" />
	<title>{eyou:global name='web_name' /}</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport" />
	<link href="{eyou:global name='web_cmspath'/}/favicon.ico" rel="shortcut icon" type="image/x-icon" />
    
    <!-- 新样式 2020-12-8 -->
    {eyou:static file="users/skin/css/element/index.css" /}
    {eyou:static file="users/skin/userfont/iconfont.css" /}
    {eyou:static file="users/skin/css/e-user.css" /}
    {eyou:include file="users/skin/css/diy_css.htm"/}
    
    
    {eyou:static file="/public/static/common/js/jquery.min.js"/}
    {eyou:static file="users/skin/js/vendor.js"/}
    {eyou:static file="/public/plugins/layer-v3.1.0/layer.js"/}
    {eyou:static file="/public/static/common/js/tag_global.js"/}
    <!--{eyou:static file="users/skin/js/iscroll.js"/}-->
</head>

<body>
    
    <!-- 头部信息 -->
    <div class="ey-header-status">
        <div class="header-status-l">
            <a href="javascript:history.go(-1)"><i class="el-icon-arrow-left"></i></a>
        </div> 
        <div class="header-status-m">我的订单</div> 
        <div class="header-status-r"></div>
    </div>
    <!-- 头部信息结束 -->
    <div class="h50"></div>
    
    <div class="ey-container order-con">
         <!-- 订单导航 -->
        {eyou:spstatus id="field3"}
        <div class="order-tab">
            <div class="tab-item {if empty($field3.select_status) && $field3.access_action == 'shop_centre'}active{/if}"><a href="{eyou:url link='user/Shop/shop_centre'/}">全部</a></div>
            <div class="tab-item {eq name='$field3.select_status' value='dzf'}active{/eq}"><a href="{eyou:url link='user/Shop/shop_centre' vars='select_status=dzf'/}">待付款</a></div>
            <div class="tab-item {eq name='$field3.select_status' value='1'}active{/eq}"><a href="{eyou:url link='user/Shop/shop_centre' vars='select_status=1'/}">待发货</a></div>
            <div class="tab-item {eq name='$field3.select_status' value='2'}active{/eq}"><a href="{eyou:url link='user/Shop/shop_centre' vars='select_status=2'/}">待收货</a></div>
        </div>
        {/eyou:spstatus}
         <!-- 没有相关订单 -->
         {eyou:empty name="$eyou.field.data"}
             <div class="order-empty">
                 <div class="icon"><i class="iconfont icon-meiyoudingdan"></i></div>
                 <div class="text">没有相关订单</div>
             </div>
         {eyou:else/}
            <div class="order-list">
                {eyou:sporderlist id="field" pagesize="10"}
                <div class="order-item">
                    <div class="order-item-t" onclick="location.href='{$field.OrderDetailsUrl}'">
                        <div class="order-item-tl">
                            <span class="img"><i class="iconfont icon-shangcheng"></i></span>
                            <span>平台自营</span>
                        </div>
                        <div class="order-item-tr">
                            <span>{$field.order_status_name}</span>
                        </div>
                    </div>
                    <div class="order-item-m" onclick="location.href='{$field.OrderDetailsUrl}'">
                        <div class="order-item-ml">
                           <div class="order-pro-box">

                               {eyou:spordergoods id="order_field" }
                               {eq name='$field.details|count' value='1'}
                               <a href="javascript:void(0);" class="pro-item one">
                                   <div class="img-box">
                                       <div class="img"><img src="{$order_field.litpic}" ></div>
                                   </div>
                                   <div class="title">
                                       {$order_field.product_name}&nbsp;
                                   </div>
                               </a>
                               {else/}
                               <a href="javascript:void(0);" class="pro-item">
                                   <div class="img"><img src="{$order_field.litpic}" ></div>
                               </a>
                               {/eq}
                               {/eyou:spordergoods}

                           </div>
                        </div>
                        <div class="order-item-mr">
                            <div class="order-price"><em>￥</em><span>{$field.order_amount}</span></div>
                            <div class="num">共{$field.order_total_num}件</div>
                        </div>
                    </div>
                    <div class="order-item-b">
                        {eyou:eq name="$field.order_status" value="0"}
                            <a class="order-btn" href="javascript:void(0);" {$field.CancelOrder}>取消订单</a>
                            <a href="{$field.PaymentUrl}" class="order-btn orange"> 立即付款 </a>
                        {/eyou:eq}

                        {eyou:eq name="$field.order_status" value="1"}
                        <a class="order-btn" href="{$field.OrderDetailsUrl}">订单详情</a>
                        <a class="order-btn orange" href="javascript:void(0);" {$field.OrderRemind}>提醒发货</a>
                        {/eyou:eq}

                        {eyou:eq name="$field.order_status" value="2"}
                        <a class="order-btn" href="{$field.OrderDetailsUrl}">订单详情</a>
                        <a href="javascript:void(0)" class="order-btn orange" {$field.Confirm} >确认收货</a>
                        {/eyou:eq}

                        {eyou:eq name="$field.order_status" value="3"}
                        {eyou:eq name="$field.is_comment" value="0"}
                        <a href="{$field.AddProduct}" class="order-btn">评价商品</a>
                        {/eyou:eq}
                        <a href="{$field.ServiceList}" class="order-btn orange">申请售后</a>
                        {/eyou:eq}

                    </div>
                </div>
                {$field.hidden}
                {/eyou:sporderlist}

                <div id="ajax_loading" style="width: 100%;height: 50px;line-height: 50px;text-align: center; display: none;">
                    <i class="el-icon-loading"></i><span>加载中</span>
                </div>
                <input type="hidden" id="unified_id">
                <input type="hidden" id="unified_number">
                <input type="hidden" id="transaction_type">  
            </div>
         {/eyou:empty}

    
    <div class="h50"></div>
    {eyou:include file="users/users_footer.htm" /}
    <div id="page_show" style="display: none">
        <div class="order-item">
            <div class="order-item-t" onclick="location.href='#OrderDetailsUrl#'">
                <div class="order-item-tl">
                    <span class="img"><i class="iconfont icon-shangcheng"></i></span>
                    <span>平台自营</span>
                </div>
                <div class="order-item-tr">
                    <span>#order_status_name#</span>
                </div>
            </div>
            <div class="order-item-m" onclick="location.href='#OrderDetailsUrl#'">
                <div class="order-item-ml">
                    <div class="order-pro-box">
                        #details#
                    </div>
                </div>
                <div class="order-item-mr">
                    <div class="order-price"><em>￥</em><span>#order_amount#</span></div>
                    <div class="num">共#order_total_num#件</div>
                </div>
            </div>
            <div class="order-item-b">
                #status_button#
            </div>
        </div>
    </div>
 </div>	

<script type="text/javascript" src="https://res.wx.qq.com/open/js/jweixin-1.3.2.js"></script>
<script type="text/javascript">
    var timers = null;
    var page = 1,last_page = 2;
    $(window).scroll(function() {
        //当时滚动条离底部60px时开始加载下一页的内容
        if (($(window).height() + $(window).scrollTop() + 30) >= $(document).height()) {
            if (last_page >= page) {
                clearTimeout(timers);
                timers = setTimeout(function() {
                    page++;
                    nextOne(page);
                }, 300);
            }
        }
    });

    function nextOne(p){
        var select_status = '{$Request.param.select_status}';
        $('#ajax_loading').css('display','block');
        $.ajax({
            url: "{eyou:url link='user/Shop/ajax_shop_centre_page'/}&page="+p,
            data: {select_status:select_status},
            type:'post',
            dataType: 'json',
            success:function(res){
                $('#ajax_loading').css('display','none');
                if (1 == res.code) {
                    last_page = res.data.pages.last_page;
                    var divhtml = $('#page_show').html();
                    var strings = '';
                    $.each(res.data.list, function(k,v) {
                        //这里的函数参数是键值对的形式，k代表键名，v代表值
                        strings = divhtml.replace('#order_status_name#', v.order_status_name);
                        strings = strings.replace('#order_amount#', v.order_amount);
                        strings = strings.replace('#order_total_num#', v.order_total_num);
                        strings = strings.replace('#OrderDetailsUrl#', v.OrderDetailsUrl);
                        strings = strings.replace('#OrderDetailsUrl#', v.OrderDetailsUrl);
                        if (1 == v.details.length){
                            var details = '<a href="javascript:void(0);" class="pro-item one">\n' +
                                '            <div class="img-box"><div class="img"><img src="'+v.details[0].litpic+'" ></div></div>\n' +
                                '            <div class="title">'+v.details[0].product_name+'&nbsp;</div>\n' +
                                '         </a>';
                            strings = strings.replace('#details#', details);
                        } else{
                            var details = '';
                            $.each(v.details, function(key,n) {
                                details += '<a href="javascript:void(0);" class="pro-item"><div class="img"><img src="'+n.litpic+'" ></div></a>';
                            })
                            strings = strings.replace('#details#', details);
                        }
                        if (0 == v.order_status) {
                            //待付款
                            var status_button = '<a href="javascript:void(0);" class="order-btn" '+v.CancelOrder+'>取消订单</a>\n' +
                                '                <a href="'+v.PaymentUrl+'" class="order-btn orange"> 立即付款 </a>';
                            strings = strings.replace('#status_button#', status_button);
                        }else if (1 == v.order_status) {
                            //待发货
                            var status_button = '<a href="'+v.OrderDetailsUrl+'" class="order-btn">订单详情</a>\n' +
                                '                <a href="javascript:void(0);" class="order-btn orange" '+v.OrderRemind+'>提醒发货</a>';
                            strings = strings.replace('#status_button#', status_button);
                        }else if (2 == v.order_status) {
                            //待收货
                            var status_button = '<a href="'+v.OrderDetailsUrl+'" class="order-btn">订单详情</a>\n' +
                                '                <a href="javascript:void(0)" class="order-btn orange" '+v.Confirm+' >确认收货</a>';
                            strings = strings.replace('#status_button#', status_button);
                        }else if (3 == v.order_status) {
                            //完成
                            var status_button = '';
                            if (0 == v.is_comment) {
                                status_button += '<a href="'+v.ServiceList+'" class="order-btn">评价商品</a>';
                            }
                             status_button += '<a href="'+v.ServiceList+'" class="order-btn orange">申请售后</a>';
                            strings = strings.replace('#status_button#', status_button);
                        }else{
                            strings = strings.replace('#status_button#', '');
                        }
                        $('.order-list').append(strings);
                    });
                    // 替换ID值
                }else {

                }
            }
        });
    }
    $(function(){
        wx.miniProgram.getEnv( function(res) {
            if(res.miniprogram) {
                // 小程序
                var i = 0;
                i = setInterval('AppletsPay()', 1000);
            }
        });
    });

    // 小程序查询
    function AppletsPay(){
        var unified_id       = $('#unified_id').val();
        var unified_number   = $('#unified_number').val();
        var transaction_type = $('#transaction_type').val();
        if (unified_id && unified_number && transaction_type) {
            $.ajax({
                url: "{eyou:url link='user/Pay/ajax_applets_pay'/}",
                data: {unified_id:unified_id, unified_number:unified_number, transaction_type:transaction_type},
                type:'post',
                dataType:'json',
                success:function(res){
                    if (1 == res.code) {
                        if (!res.data.mobile && !res.data.email) window.location.href = res.url;
                        if (res.data.mobile) SendMobile(res.data.mobile);
                        if (res.data.email) SendEmail(res.data.email);
                        window.location.href = res.url;
                    }
                }
            });    
        }
    }

	// 判断支付类型是否一致并且更新支付方式
    function UpdatePayMethod(unified_id, unified_number, transaction_type){
    	layer_loading_mini();
        $.ajax({
            url: "{eyou:url link='user/Pay/update_pay_method'/}",
            data: {unified_id:unified_id,unified_number:unified_number,pay_method:'WeChatInternal',transaction_type:transaction_type,order_source:2},
            type:'post',
            dataType:'json',
            success:function(res){
                layer.closeAll();
                if (0 == res.code) {
                	showErrorAlert(res.msg, 0);
                }else{
                    if (1 == res.data.is_gourl) {
                        window.location.href = res.url;
                    }else{
                        $('#unified_id').val(unified_id);
                        $('#unified_number').val(unified_number);
                        $('#transaction_type').val(transaction_type);
                        WeChatInternal(unified_id, unified_number, transaction_type);
                    }
                }
            }
        });
    }

	// 微信内部中进行支付
    function WeChatInternal(unified_id, unified_number, transaction_type)
    {   
        wx.miniProgram.getEnv( function(res) {
            if(res.miniprogram) {
                // 小程序
                wx.miniProgram.navigateTo({
                    url: '/pages/pay/pay?unified_id='+ unified_id +'&unified_number=' + unified_number + '&type=' + transaction_type
                });
            } else {
                // 微信端
                $.ajax({
                    url: "{eyou:url link='user/Pay/wechat_pay'/}",
                    data: {unified_id:unified_id,unified_number:unified_number,transaction_type:transaction_type},
                    type:'post',
                    dataType:'json',
                    success:function(res){
                        layer.closeAll();
                        if (1 == res.code) {
                            callpay(res.msg);
                        }else{
                        	showErrorAlert(res.msg, 0);
                        }
                    }
                });
            }
        });
    }

    //调用微信JS api 支付
    function jsApiCall(data)
    {
        WeixinJSBridge.invoke(
            'getBrandWCPayRequest',data,
            function(res){
                if(res.err_msg == "get_brand_wcpay_request:ok"){  
                    pay_deal_with();
                    // layer.msg('微信支付完成！', {time: 1000}, function(){
                    //     pay_deal_with();
                    // });
                }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
                	showErrorAlert('用户取消支付！', 0);
                }else{
                	showErrorAlert('支付失败，原因可能是订单号已支付！', 0);
                }  
            }
        );
    }
    
    // 微信内部支付时，先进行数据判断
    function callpay(data)
    {
        if (typeof WeixinJSBridge == "undefined"){
            if( document.addEventListener ){
                document.addEventListener('WeixinJSBridgeReady', jsApiCall, false);
            }else if (document.attachEvent){
                document.attachEvent('WeixinJSBridgeReady', jsApiCall); 
                document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
            }
        }else{
            jsApiCall(data);
        }
    }

    function pay_deal_with(){
        var unified_number   = $('#unified_number').val();
        var transaction_type = $('#transaction_type').val();
        $.ajax({
            url: "{eyou:url link='user/Pay/pay_deal_with'/}",
            data: {unified_number:unified_number,transaction_type:transaction_type},
            type:'post',
            dataType:'json',
            success:function(res){
                if (1 == res.data.status) {
                    if (!res.data.mobile && !res.data.email) window.location.href = res.url;
                    if (res.data.mobile) SendMobile(res.data.mobile);
                    if (res.data.email) SendEmail(res.data.email);
                    window.location.href = res.url;
                }
            }
        });
    }

    // 发送短信
    function SendMobile(result) {
        if (result) {
            $.ajax({
                url: result.url,
                data: result.data,
                type:'post',
                dataType:'json'
            });
        }
    }

    // 发送邮件
    function SendEmail(result) {
        if (result) {
            $.ajax({
                url: result.url,
                data: result.data,
                type:'post',
                dataType:'json'
            });
        }
    }
</script>
